﻿using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SharePointHelper.DLL.CSOM
{
    public class Sites
    {
        #region Values of LCID
        /* Values of LCID refer to:https://msdn.microsoft.com/en-us/library/office/jj850866.aspx
        LCID  Language
        1025  Arabic 
        1046  Brazilian
        1026  Bulgarian
        1027  Catalan
        2052  Chinese - Simplified
        1028  Chinese - Traditional
        1050  Croatian
        1029  Czech
        1030  Danish
        1043  Dutch
        1033  English
        1061  Estonian
        1035  Finnish
        1036  French
        1031  German
        1032  Greek
        1037  Hebrew
        1081  Hindi
        1038  Hungarian
        1040  Italian
        1041  Japanese
        1087  Kazakh
        1042  Korean
        1062  Latvian
        1063  Lithuanian
        1044  Norwegian
        1045  Polish
        2070  Portuguese
        1048  Romanian
        1049  Russian
        2074  Serbian
        1051  Slovak
        1060  Slovenian
        1034  Spanish
        1053  Swedish
        1054  Thai
        1055  Turkish
        1058  Ukrainian
        */
        #endregion

        #region 根据LCID获取所有子站点模板
        /// <summary>
        /// 根据LCID获取所有子站点模板
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="LCID"></param>
        /// <param name="overrideCompatLevel"></param>
        /// <returns></returns>
        public static WebTemplateCollection GetAllTemplatesWithLCID(ClientContext clientContext, uint LCID, int overrideCompatLevel=0)
        {
            WebTemplateCollection webTemplates = clientContext.Site.GetWebTemplates(LCID, overrideCompatLevel);
            return webTemplates;
        }
        #endregion

        #region 根据指定模板创建子站点
        /// <summary>
        /// 根据指定模板创建子站点
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="tempName">模板名称，例如：{80B2DB28-49E2-4666-8E3C-08736733CD43}#PCMan</param>
        /// <param name="newSiteName">新自站点的name，例如：PCManTest</param>
        /// <param name="description"></param>
        /// <param name="language">站点语言，默认为English</param>
        public static void CreateSubSiteViaTemp(ClientContext clientContext, string tempName, string newSiteName, string description,int language=1033)
        {
            WebCreationInformation webCreationInformation = new WebCreationInformation();
            webCreationInformation.WebTemplate = tempName;
            webCreationInformation.Description = description;
            webCreationInformation.Url = newSiteName;
            webCreationInformation.Title = newSiteName;
            webCreationInformation.Language = language;
            clientContext.Web.Webs.Add(webCreationInformation);
            clientContext.ExecuteQuery();
        }
        #endregion
    }
}
